/**
 * 工具类
 */
define(function (require, exports, module) {
    var $ = require("jquery");
    var UI = {
        /**
         * 创建loading
         * @param {String} id     loading创建在对应id的dom元素内容
         * @param {String} text   需要修改的文字
         * @param {String} state  判断是否成功/失败，显示对应样式
         */
        loading: function (id, text, state) {
            var str = '',
                text = text ? text : "正在加载...",
                iconCls = 'loading-icon',
                obj = "body",
                loadCls = "loading";
            // 判断是否已经有loading
            var isload = document.getElementById("loading");
            if (isload) {
                return;
            }
            var height;
            if (id) {
                obj = "#" + id;
                height = $(obj).height();
                loadCls = "loading-abs";
            } else {
                height = $(window).height();
            }
            if (state) {
                iconCls = state === "success" ? "loading-success" : "loading-false";
            }
            str += '<div id="loading" class="' + loadCls + '"><div class="loading-con"><div class="loading-img"><i class=' + iconCls + '></i></div>';
            str += '<p>' + text + '</p>';
            str += '</div></div>';
            $(obj).append(str);
            $("#loading").css("top", height / 2 - 62);
            if (state) {
                var _this = this;
                setTimeout(function () {
                    _this.removeLoading();
                }, 3500);
            }
        },
        /**
         * 删除loading
         */
        removeLoading: function () {
            $("#loading").remove();
        },
        /**
         * 操作提示
         * @param {string?} msg
         */
        showTip: function (msg) {
            msg = msg || "提示";
            this.removeLoading();
            this.loading(null, msg, "success");
        },
        /**
         * 操作成功提示
         * @param {string?} msg
         */
        showSucTip: function (msg) {
            msg = msg || "操作成功";
            this.removeLoading();
            this.loading(null, msg, "success");
        },
        /**
         * 操作失败提示
         * @param {string?} msg
         */
        showErrTip: function (msg) {
            msg = msg || "操作失败";
            this.removeLoading();
            this.loading(null, msg, "error");
        }
    };
    module.exports = UI;
});